/*
 * File Name: ApplicationList.java
 * Created on: November 13 2007, 02:39 PM
 */

package co.edu.uniandes.intercon.client.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;

import co.edu.uniandes.intercon.core.model.BaseDto;
import co.edu.uniandes.intercon.core.model.ParamDto;

/**
 * <code>Singleton</code> used to store ...
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class ProcessParamList extends Observable {

	/*
	 * Singleton instance
	 */
	private static ProcessParamList instance;

	/*
	 * application list
	 */
	private List<BaseDto> applications;

	// avoids instantiation outside the class
	private ProcessParamList() {
		applications = new ArrayList<BaseDto>();
	}

	/** Creates a new instance of Application list */
	public static synchronized ProcessParamList getInstance() {
		if (instance == null) {
			instance = new ProcessParamList();
		}
		return instance;
	}

	/**
	 * Retrieves current application list
	 * 
	 * @return application list
	 */
	public List<BaseDto> getApplicationList() {
		return applications;
	}

	/**
	 * Set the current message and notity all the observers of this class about
	 * the change
	 * 
	 * @param dto
	 *            Application to add to the list
	 */
	public void addParameter(ParamDto dto) {
		applications.add(dto);
		super.setChanged();
		super.notifyObservers();
	}

	/**
	 * Remove the element in the position specified
	 * 
	 * @param row
	 *            Row of the element to be removed
	 */
	public void remove(int row) {
		if (row >= 0) {
			applications.remove(row);
			super.setChanged();
			super.notifyObservers();
		}
	}

	/**
	 * 
	 */
	public void clear() {
		applications = new ArrayList<BaseDto>();
		super.setChanged();
		super.notifyObservers();
	}

	/**
	 * 
	 * @param params
	 */
	public void setElements(List<ParamDto> params) {
		applications.clear();
		applications.addAll(params);
		super.setChanged();
		super.notifyObservers();
	}

}
